package com.fjc.service.impl;

import com.fjc.dao.StudentMapper;
import com.fjc.domain.Student;
import com.fjc.service.StudentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by fjc on 2018/6/16.
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    @Transactional
    public void createStudent(Student student) {
        studentMapper.insertSelective(student);
        throw new RuntimeException("ddd");
    }

    @Override
//    @RequiresPermissions("user")
    @RequiresPermissions("user:createUser")
    public String shiro() {
        return "quanxian";
    }

    //当抛出的异常属于该异常时，则不回滚
    @Transactional(noRollbackFor = RuntimeException.class)
    public void createStudent1(Student student) {
        studentMapper.insertSelective(student);
        throw new RuntimeException("ddd");
    }

    //Spring的事务有七种传播机制，默认为REQUIRED，若当前有事务，则加入该事务当中，若没有事务则新起事务
    @Transactional(propagation = Propagation.REQUIRED)
    public void createStudent11(Student student) {
        studentMapper.insertSelective(student);
        throw new RuntimeException("ddd");
    }
}
